﻿namespace Leetcode.M1711;
public class Solution
{
    public int FindClosest(string[] words, string word1, string word2)
    {
        int index1 = -1;
        int ans = words.Length;
        for (int index2 = 0; index2 < words.Length; index2++)
        {
            if (words[index2] == word1 || words[index2] == word2)
            {
                if (index1 != -1 && words[index2] != words[index1])
                {
                    ans = Math.Min(ans, index2 - index1);
                }
                index1 = index2;
            }
        }
        return ans;
    }
}